//
//  CYNetWorkGetRequest.m
//  CYNetworkComponent_Example
//
//  Created by lc4y on 2018/2/15.
//  Copyright © 2018年 lc4y. All rights reserved.
//

#import "CYNetWorkGetRequest.h"
#import "CYNetworkCommonArguments.h"

@interface CYNetWorkGetRequest ()

@property (nonatomic, copy)   NSString *url;
@property (nonatomic, strong) NSDictionary *arguments;

@end

@implementation CYNetWorkGetRequest

+ (void)CYNetGetRequetWithURL:(NSString *)url params:(NSDictionary *)params complete:(void (^)(id obj,NSError *error))completion {
    CYNetWorkGetRequest *getRequet = [[CYNetWorkGetRequest alloc] init];
    getRequet.url       = url;
    getRequet.arguments = params;
    
    [getRequet startWithCompletionBlockWithSuccess:^(__kindof YTKBaseRequest * _Nonnull request) {
        completion(request.responseObject,nil);
    } failure:^(__kindof YTKBaseRequest * _Nonnull request) {
        completion(nil,request.error);
    }];
}

- (NSString *)requestUrl {
    return self.url;
}

- (YTKRequestMethod)requestMethod {
    return YTKRequestMethodGET;
}

- (NSDictionary *)requestArgument {
    NSDictionary *commonDict = [CYNetworkCommonArguments shareCommonArguments].commonArguments ? [CYNetworkCommonArguments shareCommonArguments].commonArguments : @{};
    NSMutableDictionary *finalDict = [NSMutableDictionary dictionaryWithDictionary:commonDict];
    [finalDict addEntriesFromDictionary:self.arguments];
    
    if([CYNetworkCommonArguments shareCommonArguments].delegate && [[CYNetworkCommonArguments shareCommonArguments].delegate respondsToSelector:@selector(CYNetworkFetchCommonArgumensts:)]) {
        return [[CYNetworkCommonArguments shareCommonArguments].delegate CYNetworkFetchCommonArgumensts:finalDict];
    }
    
    return finalDict;
}

@end
